package me.xplabs.fight.layer 
{
	import flash.display.BitmapData;
	import me.xplabs.engine.display.BaseDisplayContainer;
	import me.xplabs.event.MMouseEvent;
	import me.xplabs.Globals;
	import me.xplabs.magic.MagicDisplay;
	import me.xplabs.model.msg.MsgUseSkill;
	import me.xplabs.model.skill.MSkillInfo;
	import me.xplabs.utils.SimpleObjPool;
	
	/**
	 * 特效层
	 * ...
	 * @author xiaohan
	 */
	public class EffectLayer extends BaseDisplayContainer 
	{
		private var _magicPool:SimpleObjPool;
		private var _magics:Vector.<MagicDisplay>;
		public function EffectLayer() 
		{
			super();
			
			_magicPool = new SimpleObjPool(MagicDisplay, 1, 1);
			_magics = new Vector.<MagicDisplay>();
		}

		public function addMagic(p_skillInfo:MSkillInfo):void
		{
			//var tempMagic:MagicDisplay = new MagicDisplay();
			var tempMagic:MagicDisplay = _magicPool.getObj();
			tempMagic.mouseEnable = false;
			tempMagic.skilInfo = p_skillInfo;
			//tempMagic.addEventListener(MMouseEvent.CLICK, buildClickHandler);
			//tempMagic.addEventListener(MMouseEvent.ROLL_OVER, buildRollOverHandler);
			//tempMagic.addEventListener(MMouseEvent.ROLL_OUT, buildRollOutHandler);
			//tempBuild.setAnimate(100, true, p_buildInfo.frameInt);
			tempMagic.resLib[1] = [];
			var resBitmapData:* = Globals.lib.getResObj(Globals.domain.magic +"r" + p_skillInfo.hitId + ".i1");
			if (resBitmapData)
			{
				tempMagic.resLib[1].push(resBitmapData);
				var len:int = resBitmapData.length;
				for (var i:int = 1; i < len; i++) 
				{
					tempMagic.resLib[1].push(Globals.lib.getResObj(Globals.domain.magic +"r" + p_skillInfo.hitId + ".i" + (i + 1)));
				}
			}
			tempMagic.setAnimate(100, true, len);
			addChild(tempMagic);
			_magics.push(tempMagic);
		}
		override public function update(container:BitmapData):void 
		{
			super.update(container);
		}
		public function removeMagic(p_soleId:int):void 
		{
			var len:int = _magics.length;
			for (var i:int = 0; i < len; i++) 
			{
				if (_magics[i].skilInfo.soleId == p_soleId)
				{
					_magics[i].dispose();
					if (_magics[i].parent) _magics[i].parent.removeChild(_magics[i]);
					_magicPool.dispose(_magics.splice(i, 1)[0]);
					return;
				}
			}
		}
	}

}